﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Abp.Threading;
using KelonProud.Administration.Logs.Domain;
using Microsoft.EntityFrameworkCore.ChangeTracking;

namespace KelonProud.Administration.Logs
{
    public interface IKelonEntityHistoryHelper
    {
        KelonEntityChangeSet CreateEntityChangeSet(ICollection<EntityEntry> entityEntries);

        Task SaveAsync(KelonEntityChangeSet changeSet);
    }

    public static class EntityHistoryHelperExtensions
    {
        public static void Save(this IKelonEntityHistoryHelper entityHistoryHelper, KelonEntityChangeSet changeSet)
        {
            AsyncHelper.RunSync(() => entityHistoryHelper.SaveAsync(changeSet));
        }
    }
}
